package com.gui.hospital.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gui.entity.R;
import com.gui.hospital.model.Hospital;
import com.gui.hospital.service.HospitalService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Author:刘舒佳
 * Date:2024/8/22
 */
@RestController
@AllArgsConstructor
@RequestMapping("/hospital")
@CrossOrigin
public class HospitalController {
    private final HospitalService hospitalService;

    /**
     * 查询所有医院信息
     * @return
     */
    @GetMapping
    public List<Hospital> getHospital(){
        List<Hospital> list = hospitalService.list();
        return list;
    }

    /**
     * 添加医院
     * @param hospital
     * @return
     */
    @PostMapping
    public boolean addHospital(@RequestBody Hospital hospital){
        return hospitalService.save(hospital);
    }

    /**
     * 修改医院信息
     * @param hospital
     * @return
     */
    @PutMapping
    public boolean updateHospital(@RequestBody Hospital hospital){
        return hospitalService.updateById(hospital);
    }

    /**
     * 根据id删除医院
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public boolean deleteHospital(@PathVariable Integer id){
        return hospitalService.removeById(id);
    }

    /**
     * 根据查询条件查询医院
     * 根据医院名称查询医院
     * 根据医院地址查询医院
     * 根据医院类型查询医院
     * 根据医保查询医院
     * @param
     * @return
     */
    @GetMapping("/search/{currentPage}/{pageSize}")
    public Page<Hospital> searchHospital(@RequestBody Hospital hospital, @PathVariable Integer currentPage, @PathVariable Integer pageSize){
        Page<Hospital> list=hospitalService.pageList(hospital,currentPage,pageSize);
        return list;
    }

    /*
    根据医院名称查询医院信息
     */
    @GetMapping("findByName")
    public List<Hospital> findByName(@RequestParam(value="name",required = false) String name){
        List<Hospital> list=hospitalService.findByName(name);
        return list;
    }

}
